package com.changgou.system.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.net.InetSocketAddress;


@Component
public class UrlFilter implements GlobalFilter, Ordered {
    //过滤器具体的业务逻辑实现
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println("经过了第二个过滤器");
        //获取客户端的访问url
        ServerHttpRequest request = exchange.getRequest();
        String path = request.getURI().getPath();
        System.out.println("url"+path);
        //放行 不放行的不会执行
        return chain.filter(exchange);
    }


    //定义过过滤器执行的优先级 返回值越小执行的优先级越高
    @Override
    public int getOrder() {
        return 2;
    }
}
